#include "myhttpd.h"
#include "list_client.h"
#include "initialize.h"
#include "create_socket.h"

extern s_configuration *g_config;

void svr_init(int *svr_socket)
{
  g_config = malloc(sizeof (s_configuration));
  config_init(NULL, 4242, NULL, NULL, 0);

  *svr_socket = create_socket();
}

void config_init(char *config_file, int port, char *root_dir,
		 char *pid_file, pid_t pidsvr)
{
  if (g_config != NULL)
  {
    g_config->config_file = config_file;
    g_config->port = port;
    g_config->root_dir = root_dir;
    g_config->pid_file = pid_file;
    g_config->pidsvr = pidsvr;
  }
}

void select_list_init(s_client *client_list, fd_set *select_list, int svr_socket)
{
  s_client *tmp = client_list;

  FD_ZERO(select_list);
  FD_SET(svr_socket, select_list);

  while (tmp != NULL)
  {
    FD_SET(tmp->socket, select_list);
    tmp = tmp->next;
  }
}
